package com.intct.hbase.ddl.impl;

import com.intct.hbase.ddl.AbsDDLSerivce;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-09-29 15:15
 */
public class DropTable extends AbsDDLSerivce {

    private String namespace;
    private String tName;

    public DropTable(String namespace, String tName) {
        this.namespace = namespace;
        this.tName = tName;
    }

    @Override
    public void execCommand(Admin admin) {
        // 创建TableName对象
        TableName tableName = TableName.valueOf(namespace, tName);

        try {
            // 判断表存在，则删除
            if (admin.tableExists(tableName)) {
                // 禁用表
                admin.disableTable(tableName);

                // 删除表
                admin.deleteTable(tableName);
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args) throws IOException {
        new DropTable("intct85", "t1_api").start();
    }
}
